package com.education.expenses.service;

import com.education.expenses.eao.UserEAO;
import com.education.expenses.entity.User;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * User: Alex Kasianik
 * Date: 13.08.12
 * Time: 6:17
 */

@Service
public class DefaultUserSetupService {
    @Autowired
    private UserEAO userEAO;

    @Autowired
    private SecurityService securityService;

    @Autowired
    private List<User> defaultUsers;

    @Transactional(propagation = Propagation.REQUIRED, readOnly = false)
    public void createDefaultUsers() {
        if (!userEAO.isUsersExist()) {
            for (User user : defaultUsers) {
                securityService.secureUserPassword(user);
                userEAO.save(user);
            }
        }
    }
}